package com.zycfc.zsf.boot.mybatis.generator.codegen.model;

import java.util.*;

public class TableModel
{
    private String tableName;
    private String tabComment;
    private String foreignKey;
    private Map<String, String> variables;
    private List<ColumnModel> columnList;
    private List<TableModel> subTableList;
    private boolean sub;
    
    public TableModel() {
        this.foreignKey = "";
        this.variables = new HashMap<String, String>();
        this.columnList = new ArrayList<ColumnModel>();
        this.subTableList = new ArrayList<TableModel>();
    }
    
    public String getTableName() {
        return this.tableName;
    }
    
    public void setTableName(final String tableName) {
        this.tableName = tableName;
    }
    
    public String getTabComment() {
        return this.tabComment.replaceAll("\r\n", "");
    }
    
    public void setTabComment(final String tabComment) {
        this.tabComment = tabComment;
    }
    
    public boolean isSub() {
        return this.sub;
    }
    
    public void setSub(final boolean sub) {
        this.sub = sub;
    }
    
    public boolean getSub() {
        return this.sub;
    }
    
    public List<ColumnModel> getColumnList() {
        return this.columnList;
    }
    
    public List<ColumnModel> getPkList() {
        final List<ColumnModel> list = new ArrayList<ColumnModel>();
        for (final ColumnModel col : this.columnList) {
            if (col.getIsPK()) {
                list.add(col);
            }
        }
        return list;
    }
    
    public ColumnModel getPkModel() {
        for (final ColumnModel col : this.columnList) {
            if (col.getIsPK()) {
                return col;
            }
        }
        return null;
    }
    
    public List<ColumnModel> getCommonList() {
        final List<ColumnModel> list = new ArrayList<ColumnModel>();
        for (final ColumnModel col : this.columnList) {
            if (!col.getIsPK()) {
                list.add(col);
            }
        }
        return list;
    }
    
    public void setColumnList(final List<ColumnModel> columnList) {
        this.columnList = columnList;
    }
    
    public List<TableModel> getSubTableList() {
        return this.subTableList;
    }
    
    public void setSubTableList(final List<TableModel> subTableList) {
        this.subTableList = subTableList;
    }
    
    public String getForeignKey() {
        return this.foreignKey;
    }
    
    public void setForeignKey(final String foreignKey) {
        this.foreignKey = foreignKey;
    }
    
    public Map<String, String> getVariables() {
        return this.variables;
    }
    
    public void setVariables(final Map<String, String> variables) {
        this.variables = variables;
    }
    
    @Override
    public String toString() {
        return "TableModel [tableName=" + this.tableName + ", tabComment=" + this.tabComment + ", foreignKey=" + this.foreignKey + ", variables=" + this.variables + ", columnList=" + this.columnList + ", subTableList=" + this.subTableList + ", sub=" + this.sub + "]";
    }
}
